/**
 * Author: david.deng<david.deng@jcinfotech.com>
 * Date: 2018/12/05
 */
import { JcToken } from '../../api/entities/common';
import { useCache } from '../../hooks/global/useCache';

const { wsCache } = useCache('localStorage');

export class TokenManager {
  static TokenCacheKey = '__AccountToken';

  getToken(): JcToken {
    const token = wsCache.get(TokenManager.TokenCacheKey);
    if (token && token.Token) {
      return token;
    }
    return new JcToken();
  }

  setToken(token?: JcToken) {
    token = token || new JcToken();
    wsCache.set(TokenManager.TokenCacheKey, token);
  }
}

export default new TokenManager();
